home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MEMORY.SWG / 0062_386 copy-move.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  2KB  |  105 lines

  1. {
  2. I wrote some substitutes for Move and Copy in Turbo Pascal 7.0 that use
  3. 386-instructions (sort of).  Some initial tests showed 30-40% improve-
  4. ment in speed.
  5.  
  6. I am posting these here for the public domain, and hance I make no
  7. guarantees for how well they work.  If you find bugs or make any
  8. optimizations, drop me a line...
  9. }
  10.  
  11. (* XFUNC.PAS v0.01 by Robert Rothenburg Walking-Owl, June 1, 1994 *)
  12. (* 32-bit "X-Functions" for Turbo Pascal 7.0                      *)
  13.  
  14. {$DEFINE USE386}
  15.  
  16. { if you $UNDEF USE386, normal 8086 instructions will be used; this
  17.   way the only change that needs to be made if you want to write '86
  18.   and '386 versions is to recompile this unit with the appropriate
  19.   define... }
  20.  
  21. unit XFunc;
  22.  
  23. interface
  24.  
  25. procedure XMove(var source, dest; size: word);
  26. function XCopy(source: string; soffs, size: byte): string;
  27.  
  28. implementation
  29.  
  30.           { Works the same as Move(source,dest,size); }
  31.  
  32. procedure XMove(var source, dest; size: word); assembler;
  33. asm
  34.         push    ds
  35.         push    es
  36.         lds     si, source
  37.         les     di, dest
  38.         mov     cx, size
  39.         cld
  40.         shr     cx, 1
  41.         jnc     @word1
  42.         movsb
  43. @word1:
  44. {$IFDEF USE386}
  45.         shr     cx, 1
  46.         jnc     @word2
  47.         movsw
  48. @word2: db      0f3h, 066h, 0a5h  { rep movsd }
  49. {$ELSE}
  50.         rep     movsw
  51. {$ENDIF}
  52.         pop     es
  53.         pop     ds
  54. end;
  55.  
  56.      { works the same as Copy(str, index, len); }
  57.  
  58.  
  59. function XCopy(source: string; soffs, size: byte): string; assembler;
  60. asm
  61.         push    ds
  62.         push    es
  63.         lds     si, source
  64.         les     di, @result
  65.         xor     ax, ax
  66.         mov     bx, ax
  67.         mov     cx, ax
  68.         mov     bl, soffs
  69.         mov     cl, size
  70.         cld
  71.         stosb
  72.         lodsb
  73.         cmp     ax, bx
  74.         jb      @done
  75.         add     si, bx
  76.         dec     si
  77.         sub     ax, bx
  78.         cmp     ax, cx
  79.         jnb     @docop
  80.         xchg    ax, cx
  81.         inc     cx
  82. @docop: push    cx
  83.         shr     cx, 1
  84.         jnc     @word1
  85.         movsb
  86. @word1:
  87. {$IFDEF USE386}
  88.         shr     cx, 1
  89.         jnc     @word2
  90.         movsw
  91. @word2: db      0f3h, 066h, 0a5h  { rep movsd }
  92. {$ELSE}
  93.         rep     movsw
  94. {$ENDIF}
  95.         pop     ax
  96.         les     di, @result
  97.         stosb
  98. @done:
  99.         pop     es
  100.         pop     ds
  101. end;
  102.  
  103. end.
  104.  
  105.